/*
 * @Author: czy
 * @Date: 2021-05-19 16:32:59
 * @LastEditTime: 2021-05-29 20:43:46
 */
#include "vsprintf.h"
#include "datetime.h"
#include "exception.h"

#include "dev/hardware/i8259.h"

#include "api/system.h"

/**
 * @description: Clear exception information after a period of time.
 */
static void clear_int(void)
{
    char temp[50] = "";
    sprintf(temp, "%30c", ' ');
    gotoxy(0, 24, temp, 0);
}

/**
 * @description: The default exception handler.
 */
void ignoreIntBody(void)
{
    gotoxy(0, 24, "\033[31mUnknown interrupt\033[0m", 0);
    setTimeout(clear_int, 2000);
    throw;
}

/**
 * @description: The keyboardInterrupt handler.
 */
void keyboardInterrupt(void)
{
    gotoxy(0, 24, "\033[31mKeyboardInterrupt\033[0m", 0);
    setTimeout(clear_int, 2000);
    disable8259();
    setTimeout(enable8259, 2000);
}